package com.util.description;

/**
 * @author yutianhong
 * @version 1.0
 * @since 2024/01/01 23:14
 */
public interface ArrayTypeDesc extends TypeDesc {

    static ArrayTypeDesc of(TypeDesc componentType) {
        return new DefaultArrayTypeDesc(componentType);
    }

    @Override
    default boolean isArray() {
        return true;
    }

    TypeDesc getComponentType();

}

class DefaultArrayTypeDesc implements ArrayTypeDesc {

    TypeDesc componentType;

    public DefaultArrayTypeDesc(TypeDesc componentType) {
        this.componentType = componentType;
    }

    @Override
    public String className() {
        return "[" + (componentType.isPrimitive() ? "" : "L") + componentType.className();
    }

    @Override
    public TypeDesc getComponentType() {
        return componentType;
    }
}


